package gretha.modelsDeJTable;

import gretha.donnees.Prelevement;

import javax.swing.table.AbstractTableModel;

public class PrelevementTableModel extends AbstractTableModel {


	private static final long serialVersionUID = -2388694431639190385L;

	private Prelevement[] _data;
	private String[] _colName = { "Année", "Volume", "%BI", "%BO" };

	public PrelevementTableModel(Prelevement[] data) {
		super();
		_data = data;
	}

	public int getColumnCount() {
		return _colName.length;
	}

	public String getColumnName(int columnIndex) {
		return _colName[columnIndex];
	}

	public int getRowCount() {
		return _data == null ? 0 : _data.length;
	}

	public Object getValueAt(int rowIndex, int columnIndex) {

		switch (columnIndex) {
		case 0:
			return new Integer(_data[rowIndex].getAnnee());
		case 1:
			return new Double(_data[rowIndex].getVolume());
		case 2:
			return new Double(_data[rowIndex].getPourcentageBI());
		case 3:
			return new Double(_data[rowIndex].getPourcentageBO());
		}
		return "";
	}

	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}

	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
	}

	public Class<? extends Object> getColumnClass(int columnIndex) {
		switch (columnIndex) {
		case 0:
			return Integer.class;
		case 1:
			return Double.class;
		case 2:
			return Double.class;
		case 3:
			return Double.class;
		default:
			return Object.class;
		}
	}

}
